import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/login/MobileLogin.vue"),
  },
  {
    path: "/login2",
    name: "login2",
    component: () => import("@/views/login/PwLogin.vue"),
  },
  {
    path: "/roadmap",
    name: "roadmap",
    component: () => import("@/views/onroad/RoadMap.vue"),
  },
  {
    path: "/mylocation",
    name: "mylocation",
    component: () => import("@/views/onroad/NowLocation.vue"),
  },
  {
    path: "/senderr",
    name: "senderr",
    component: () => import("@/views/onroad/SendErr.vue"),
  },
  {
    path: "/misson",
    name: "misson",
    component: () => import("@/views/onroad/MissonList.vue"),
    children: [
      {
        path: "/task",
        name: "task",
        component: () => import("@/views/onroad/TaskList.vue"),
      },
    ],
  },
  {
    path: "/carback",
    name: "carback",
    component: () => import("@/views/onroad/CarBack.vue"),
  },
  {
    path: "/missondetail",
    name: "missondetail",
    component: () => import("@/views/onroad/MissionDetail.vue"),
  },
  {
    path: "/errshow",
    name: "errshow",
    component: () => import("@/views/onroad/ErrShow.vue"),
  },
];

let originPush = VueRouter.prototype.push;
let originReplace = VueRouter.prototype.replace;
// push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  // if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originPush.call(this, location).catch((err) => {
    return;
  });
};
// replace
VueRouter.prototype.replace = function replace(location, onResolve, onReject) {
  // if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
  return originReplace.call(this, location).catch((err) => err);
};

const router = new VueRouter({
  routes,
});

export default router;
